# -*- coding: utf-8 -*-
"""
@date: 2021/6/22 15:38
@file: K_greater_use.py
@author: lilong
@desc: 
"""

import numpy as np
import keras.backend as K
from keras.layers import Lambda

x_test = np.array(
    [[[1, 2],
      [2, 3],
      [3, 4],
      [4, 5]]])
print(x_test.shape)

xx = K.expand_dims(x_test, 2)

# 比较x_test的每个元素和3的大小，返回布尔值
m1 = K.greater(x_test, 3)
print("m1:", m1)

# 布尔值转换为浮点数
m2 = K.cast(m1, "float32")
print("m2:", m2)


from keras.models import Input, Model
mm = Input(shape=(4, 2))
qq = Lambda(lambda x: K.cast(K.greater(K.expand_dims(x, 2), 3), 'float32'))(mm)
print("qq:", qq)
model = Model(mm, qq)
print(model.predict(x_test))


